// 用户相关的接口请求函数都在这里
import type { CodeType, User, UserInfo, Patient } from '@/types/user' //设置传的是user类型，自动导入
import { request } from '@/utils/rquest'

// 密码登录
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'POST', { mobile, password }) //返回的是一个promise
}

// 发送验证码
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request('/code', 'GET', { mobile, type }) //<user>可加可不加。因为不用
}

// 短信登录
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

// 获取个人信息
export const getUserInfo = () => {
  // 不需要传参，已经登录了
  return request<UserInfo>('/patient/myUser')
}

// 获患者信息列表
export const getPatientList = () => {
  return request<Patient[]>('/patient/mylist')
}

// 添加患者信息
export const addPatient = (patient: Patient) => {
  return request('/patient/add', 'POST', patient)
}

// 编辑患者信息
export const updatePatient = (patient: Patient) => {
  return request('/patient/update', 'PUT', patient)
}

// 删除患者信息
export const deletePatient = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}

// 查询患者详情
export const getPatientDetial = (id: string) => request<Patient>(`/patient/info/${id}`)

// qq登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// 登录--绑定用户新-三方登录绑定手机号
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<User>('/login/binding', 'POST', data)
